#include <iostream>

#include "Monster.h"
#include "Random.h"

using namespace std;


/**
 * Constructor
 * All members are set to 0.
 */
Monster::Monster()
{
	m_initHP.mLow = 0;
	m_initHP.mHigh = 0;
	m_initGold.mLow = 0;
	m_initGold.mHigh = 0;
}


/**
 * Destructor
 *
 */
Monster::~Monster()
{
}


/**
 * operator=
 * Overloaded assigment operator.
 * @param const Monster& monsterToCopy - which is the Class to copy
 * @return Monster& - a reference to the copied Class
 *
 */
Monster& Monster::operator=(const Monster& monsterToCopy)
{
	if (this != &monsterToCopy)
	{
		m_strName = monsterToCopy.m_strName;
		m_iHP = monsterToCopy.m_iHP;
		m_iMaxHP = monsterToCopy.m_iMaxHP;
		m_iMP = monsterToCopy.m_iMP;
		m_iMaxMP = monsterToCopy.m_iMaxMP;
		m_iXP = monsterToCopy.m_iXP;
		m_iLevel = monsterToCopy.m_iLevel;
		m_iGold = monsterToCopy.m_iGold;
		m_iPhysicalAttack = monsterToCopy.m_iPhysicalAttack;
		m_iPhysicalDefense = monsterToCopy.m_iPhysicalDefense;
		m_iMagicalAttack = monsterToCopy.m_iMagicalAttack;
		m_iMagicalDefense = monsterToCopy.m_iMagicalDefense;
		m_iEvasion = monsterToCopy.m_iEvasion;
		m_initHP.mLow = monsterToCopy.m_initHP.mLow;
		m_initHP.mHigh = monsterToCopy.m_initHP.mHigh;
		m_initGold.mLow = monsterToCopy.m_initGold.mLow;
		m_initHP.mHigh = monsterToCopy.m_initHP.mHigh;
		// Copy equipment
		for (unsigned int i = 0; i < monsterToCopy.m_equipment.size(); ++i)
		{
			Item* newItem = new Item;

			*(newItem) = *(monsterToCopy.m_equipment[i]);
			m_equipment.push_back(newItem);
			if (monsterToCopy.m_equipment[i]->getId() == monsterToCopy.m_rightHand->getId())
			{
				m_rightHand = newItem;
			}
			if (monsterToCopy.m_equipment[i]->getId() == monsterToCopy.m_leftHand->getId())
			{
				m_leftHand = newItem;
			}
			if (monsterToCopy.m_equipment[i]->getId() == monsterToCopy.m_body->getId())
			{
				m_body = newItem;
			}
			for (unsigned int i = 0; i < monsterToCopy.m_backpack.size(); ++i)
			{
				if (monsterToCopy.m_equipment[i]->getId() == monsterToCopy.m_backpack[i]->getId())
				{
					m_backpack.push_back(newItem);
					break;
				}
			}
		}
	}
	return *this;
}


/**
 * Set lower range of initial HP
 * @param int val
 * @return void
 */
void Monster::set_hp_min(int val)
{
	m_initHP.mLow = val;
}


/**
 * Set higher range of initial HP
 * @param int val
 * @return void
 */
void Monster::set_hp_max(int val)
{
	m_initHP.mHigh = val;
}


/**
 * Set lower range of initial Gold amount
 * @param int val
 * @return void
 */
void Monster::set_gold_min(int val)
{
	m_initGold.mLow = val;
}


/**
 * Set higher range of initial Gold amount
 * @param int val
 * @return void
 */
void Monster::set_gold_max(int val)
{
	m_initGold.mHigh = val;
}


/**
 * Print specific Class info
 * @param void
 * @return void
 */
void Monster::printSpecific()
{
	cout << "------------------------------------------------" << endl;
	cout << "Minimum HP = " << m_initHP.mLow << "\t\t\t Maximum HP " << m_initHP.mHigh << endl;
	cout << "Minimum Gold = " << m_initGold.mLow << "\t\t\t Maximum Gold " << m_initGold.mHigh << endl;
}


/**
 * Set Initial HP and Gold amount of the Monster
 * @param void
 * @return void
 */
void Monster::generate()
{
	setInitHP(Random(m_initHP.mLow, m_initHP.mHigh));
	setGold(Random(m_initGold.mLow, m_initGold.mHigh));
}
